from __future__ import print_function
#####################################################
# Author: Christian Askeland, SINTEF Medical Technology
# Date:   2013.01.30
#
# Description:
#
#             
#################################################             

def _contained(line, filters):
    '''
    return true is line contains one of the filters
    '''
    for onefilter in filters:
        if onefilter in line:
            return True
    return False

def clean_sloccount(infile, outfile, filters):
    '''
    Remove parts of output generated by sloccount.

    Remove all lines in infile containing one of the strings in filter,
    send result to outfile.
    Filter is whitespace-separated.
    '''
    filters = filters.split(' ')
    print('Removing all lines in %s containing one of:\n%s' % (infile, '\n'.join(filters)))

    with open(infile, 'r') as f:
        read_data = f.read()
    
    lines = read_data.split('\n')
    cleanlines = [x for x in lines if not _contained(x, filters)]
    out_text = '\n'.join(cleanlines) + '\n'

    # write to outfile
    f = open(outfile, 'w')
    f.write(out_text)
    f.close()

